//
//  Personal_InformationViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/5.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Personal_InformationViewController.h"

#import "HeadSculpture_ViewController.h"
#import "Eidt_InformationViewController.h"

@interface Personal_InformationViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

@property (nonatomic, strong) UILabel * user_Tel;

@end

@implementation Personal_InformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"个人资料";
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 35, 15)];
    lbl_return.text = @"返回";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 60, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //右编辑
    UIButton * btn_Edit = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_Edit.frame = CGRectMake(SCREEN_WIDTH - 5 - 50, 20 + 7, 50, 30);
    [btn_Edit setTitle:@"编辑" forState:(UIControlStateNormal)];
    [btn_Edit setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn_Edit.titleLabel.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:btn_Edit];
    [btn_Edit addTarget:self action:@selector(btn_EditAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//右编辑
- (void )btn_EditAction:(UIButton *)sender
{
//    NSLog(@"点击进入编辑资料详情");
    
    Eidt_InformationViewController * eidt_InformationViewController = [[Eidt_InformationViewController alloc] init];
    [self showViewController:eidt_InformationViewController sender:nil];
}

//tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
    
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return 70;
    }
    else if(indexPath.row == 4)
    {
        return 10;
    }
    else
    {
        return 50;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    
    switch (indexPath.row)
    {
        case 0:
        {
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            //头像
            UIImageView * image_heads = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 50, 50)];
            image_heads.userInteractionEnabled = YES;
            image_heads.layer.masksToBounds = YES;
            image_heads.layer.cornerRadius = 25;
            image_heads.image = [UIImage imageNamed:@"heads.jpg"];
            [cell addSubview:image_heads];
            //
            UIButton * btn_imageHeads = [UIButton buttonWithType:(UIButtonTypeSystem)];
            btn_imageHeads.frame = CGRectMake(0, 0, 50, 50);
            [image_heads addSubview:btn_imageHeads];
            [btn_imageHeads addTarget:self action:@selector(btn_imageHeadsAction:) forControlEvents:(UIControlEventTouchUpInside)];
            
            //姓名
            UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, SCREEN_WIDTH - 120, 20)];
            name.text = @"员工名称";
            name.textColor = [UIColor blackColor];
            name.font = [UIFont systemFontOfSize:17];
            [cell addSubview:name];
            
            //职位
            UILabel * job_Title = [[UILabel alloc] initWithFrame:CGRectMake(100, CGRectGetMaxY(name.frame) + 10, SCREEN_WIDTH - 120, 15)];
            job_Title.text = @"销售经理";
            job_Title.textColor = [UIColor grayColor];
            job_Title.font = [UIFont systemFontOfSize:15];
            [cell addSubview:job_Title];
            
            //
            UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 69, SCREEN_WIDTH, 1)];
            view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_line];
        }
            break;
        case 1:
        {
            UILabel * lbl_Sex = [[UILabel alloc] initWithFrame:CGRectMake(15, 17.5, 50, 15)];
            lbl_Sex.text = @"性别";
            lbl_Sex.textColor = [UIColor grayColor];
            lbl_Sex.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_Sex];
            
            UILabel * user_Sex = [[UILabel alloc] initWithFrame:CGRectMake(100, 17.5, SCREEN_WIDTH - 120, 15)];
            user_Sex.text = @"男";
            user_Sex.textColor = [UIColor blackColor];
            user_Sex.font = [UIFont systemFontOfSize:15];
            [cell addSubview:user_Sex];
            
            //
            UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
            view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_Line];
        }
            break;
        case 2:
        {
            UILabel * lbl_Tel = [[UILabel alloc] initWithFrame:CGRectMake(15, 17.5, 50, 15)];
            lbl_Tel.text = @"手机";
            lbl_Tel.textColor = [UIColor grayColor];
            lbl_Tel.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_Tel];
            
            self.user_Tel = [[UILabel alloc] initWithFrame:CGRectMake(100, 17.5, SCREEN_WIDTH - 120, 15)];
            self.user_Tel.text = @"1866999XXXX";
            self.user_Tel.textColor = [UIColor blackColor];
            self.user_Tel.font = [UIFont systemFontOfSize:15];
            [cell addSubview:self.user_Tel];
            
            //
            UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
            view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_Line];
            
            
            UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressCellHandle:)];
            longPressGesture.minimumPressDuration = 0.9;
            [cell addGestureRecognizer:longPressGesture];
        }
            break;
        case 3:
        {
            UILabel * lbl_Mail = [[UILabel alloc] initWithFrame:CGRectMake(15, 17.5, 50, 15)];
            lbl_Mail.text = @"邮箱";
            lbl_Mail.textColor = [UIColor grayColor];
            lbl_Mail.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_Mail];
            
            UILabel * user_Mail = [[UILabel alloc] initWithFrame:CGRectMake(100, 17.5, SCREEN_WIDTH - 140, 15)];
            user_Mail.text = @"1057008XXX@qq.com";
            user_Mail.textColor = [UIColor blackColor];
            user_Mail.font = [UIFont systemFontOfSize:15];
            [cell addSubview:user_Mail];
            
            UIButton * btn_Mail = [UIButton buttonWithType:(UIButtonTypeSystem)];
            btn_Mail.frame = CGRectMake(SCREEN_WIDTH - 40, 10, 30, 30);
            [btn_Mail setBackgroundImage:[UIImage imageNamed:@"Mail.png"] forState:(UIControlStateNormal)];
            [cell addSubview:btn_Mail];
            [btn_Mail addTarget:self action:@selector(btn_MailAction:) forControlEvents:(UIControlEventTouchUpInside)];
            
            //
            UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
            view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_Line];
        }
            break;
        case 4:
        {
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
        }
            break;
        case 5:
        {
            UILabel * lbl_Leader = [[UILabel alloc] initWithFrame:CGRectMake(15, 17.5, 80, 15)];
            lbl_Leader.text = @"直属上级";
            lbl_Leader.textColor = [UIColor grayColor];
            lbl_Leader.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_Leader];
            
            UILabel * user_Leader = [[UILabel alloc] initWithFrame:CGRectMake(100, 17.5, SCREEN_WIDTH - 120, 15)];
            user_Leader.text = @"销售总监-XXX";
            user_Leader.textColor = [UIColor blackColor];
            user_Leader.font = [UIFont systemFontOfSize:15];
            [cell addSubview:user_Leader];
            
            //
            UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
            view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_Line];
        }
            break;
        case 6:
        {
            UILabel * lbl_Department = [[UILabel alloc] initWithFrame:CGRectMake(15, 17.5, 50, 15)];
            lbl_Department.text = @"部门";
            lbl_Department.textColor = [UIColor grayColor];
            lbl_Department.font = [UIFont systemFontOfSize:15];
            [cell addSubview:lbl_Department];
            
            UIView * view_Line1 = [[UIView alloc] initWithFrame:CGRectMake(87, 24, 7, 2)];
            view_Line1.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_Line1];
            
            UILabel * user_Department = [[UILabel alloc] initWithFrame:CGRectMake(100, 17.5, SCREEN_WIDTH - 120, 15)];
            user_Department.text = @"销售XXX部";
            user_Department.textColor = [UIColor blackColor];
            user_Department.font = [UIFont systemFontOfSize:15];
            [cell addSubview:user_Department];
            
            //
            UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
            view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
            [cell addSubview:view_Line];
        }
            break;
        default:
            break;
    }
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - 点击查看图片详情
- (void )btn_imageHeadsAction:(UIButton *)sender
{
//    NSLog(@"点击查看图片详情");
    
    HeadSculpture_ViewController * headSculpture_ViewController = [[HeadSculpture_ViewController alloc] init];
    headSculpture_ViewController.str_image = @"heads.jpg";
    [self.navigationController presentViewController:headSculpture_ViewController animated:YES completion:^{
        
    }];
}

#pragma mark - 点击进入邮件
- (void )btn_MailAction:(UIButton *)sender
{
//    NSLog(@"点击进入邮件");
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://"]];
}

#pragma mark - 长按及出现复制按钮
-(void)longPressCellHandle:(UILongPressGestureRecognizer *)gesture
{
    [self becomeFirstResponder];
    
    UIMenuController * menuController = [UIMenuController sharedMenuController];
    UIMenuItem *copyItem = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(menuCopyBtnPressed:)];
    menuController.menuItems = @[copyItem];
    [menuController setTargetRect:gesture.view.frame inView:gesture.view.superview];
    [menuController setMenuVisible:YES animated:YES];
    
    [UIMenuController sharedMenuController].menuItems = nil;
}

-(void)menuCopyBtnPressed:(UIMenuItem *)menuItem
{
    [UIPasteboard generalPasteboard].string = self.user_Tel.text;
}

-(BOOL)canBecomeFirstResponder
{
    return YES;
}

@end
